<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>待审核攻略点评管理</title>
    <#include "../common/header.ftl"/>
    <#include "../common/page.ftl"/>

    <script type="text/javascript">
        $(function () {
            // 发送ajax请求获取当前攻略点评内容显示在模态框中,图片+内容
            $('.lookBtn').click(function () {
                var id = $(this).data('id');
                $.get('/strategyComment/getImgUrlAndContent.do',{id:id},function (data) {
                    // 清空模态框内容,繁殖占着茅坑不拉屎
                    $('#showModal .modal-body').html('');
                    // 将内容拼接到模态框中
                    var contentHtml = '<p>'+data.content+'</p>';
                    $('#showModal .modal-body').append(contentHtml);
                    // 将多张图片拼接到模态框中
                    var imgUrls = '';
                    $.each(data.imgUrlsArr,function (index, item) {
                        imgUrls += '<img src="'+item+'"/><hr>'
                    })
                    $('#showModal .modal-body').append(imgUrls);
                    $('#showModal').modal('show');
                })
            })
            // 修改攻略点评的状态和头条推荐时间
            $('.changeBtn').click(function () {

                // 获取模态框回显数据
                var json = $(this).data('json');
                console.log(json);
                // 良好的变成习惯:清空模态框
                $('#editForm').val('');
                // 将数据设置到模态框中
                $('#editForm input[name="id"]').val(json.id);
                $('#editForm input[name="commendTime"]').val(json.commendTime);
                $('#editForm select[name="state"]').val(json.state);
                // 弹出模态框
                $('#editModal').modal('show');
            })
            // 更新
            $('.btn_submit').click(function () {
                // 异步表单提交
                $('#editForm').ajaxSubmit(function (data) {
                    if(data.success){
                        alert("修改成功");
                        window.location.reload();
                    }else{
                        alert(data.msg);
                    }
                })
            })


        })

    </script>
    <style type="text/css">
        #showModal img {
            width: 100%;
        }

        #showModal .modal-body {
            max-height: 600px;
            overflow-y: auto;
        }
    </style>
</head>

<body>

<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "strategyComments" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>待审核攻略点评管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/strategyComment/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                        <label>状态</label>
                        <select name="state" class="form-control">
                            <option value="-1">全部</option>
                            <option value="0">待审核</option>
                            <option value="1">审核通过</option>
                        </select>
                        <label>所属攻略</label>
                        <select name="strategyId" class="form-control">
                            <option value="-1">全部</option>
                            <#list strategies as s>
                                <option value="${s.id}">${s.title}</option>
                            </#list>
                        </select>
                        <script>
                            $('#searchForm select[name=state]').val(${qo.state});
                        </script>
                        <script>
                            $('#searchForm select[name=strategyId]').val(${qo.strategyId});
                        </script>
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>用户昵称</th>
                        <th>创建时间</th>
                        <th>所属攻略</th>
                        <th>状态</th>
                        <th>头条推荐时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
					<#list result.list as sc>
                    <tr>
                        <td>${sc_index+1!}</td>
                        <td>${(sc.user.nickName)!}</td>
                        <td>${(sc.createTime?string("yyyy-MM-dd"))!}</td>
                        <td>${sc.strategy.title!}</td>
                        <td>${sc.state!}</td>
                        <td>${(sc.commendTime?string("yyyy-MM-dd"))!}</td>
                        <td>
                            <a href="javascript:;" class="btn btn-primary lookBtn" data-id="${sc.id}" >查看文章</a>
                            <a href="javascript:;" class="btn btn-success changeBtn" data-json='${sc.JSONStr!}'>修改</a>
                        </td>
                    </tr>
                    </#list>
                    </tbody>
                </table>

                <div style="text-align: center;">
                    <ul id="pagination" class="pagination"></ul>
                </div>
            </div>
        </div>
    </div>
</div>
<#--查看点评内容-->
<div class="modal fade" id="showModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">攻略点评详情</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>
<#--修改-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyComment/update.do" method="post" id="editForm" >
                    <input type="hidden" value="" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">头条推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="commendTime" onclick="WdatePicker()" readonly>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select name="state" class="form-control">
                                <option value="-1">请选择状态</option>
                                <option value="0">待审核</option>
                                <option value="1">审核通过</option>
                            </select>
                        </div><br>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">保存</button>
                <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>